//
//  ViewController.m
//  ZIVSetView
//
//  Created by ziv on 16/9/8.
//  Copyright © 2016年 Ziv. All rights reserved.
//

#import "HMSettingViewController.h"
#import "feedbackViewController.h"
#import "WebViewController.h"
#import "YiBaoViewController.h"
#import "AboutViewController.h"
static NSString *cellID = @"cellID";
@interface HMSettingViewController ()<UITableViewDelegate,UITableViewDataSource>

@end

@implementation HMSettingViewController

- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath
{
    NSLog(@"%zd--%zd",indexPath.section,indexPath.row);
    [tableView deselectRowAtIndexPath:indexPath animated:true];
    if (indexPath.row == 0 && indexPath.section == 0)
    {
        
    feedbackViewController *vc = [[feedbackViewController alloc]init];
    [self.navigationController pushViewController:vc animated:YES];
  
    
    }else if (indexPath.row == 1 && indexPath.section ==0)
    {
        WebViewController *webVC = [[WebViewController alloc]init];
        [self.navigationController pushViewController:webVC animated:YES];
    
    
    }else if (indexPath.row == 2 && indexPath.section == 0)
    {
        UIAlertController *alertController = [UIAlertController alertControllerWithTitle:@"温馨提示" message:@"确定清除缓存吗" preferredStyle:UIAlertControllerStyleAlert];
        //确定action
        UIAlertAction *confirmAction = [UIAlertAction actionWithTitle:@"确定" style:UIAlertActionStyleDefault handler:nil];
        //取消
        UIAlertAction *cancelAction = [UIAlertAction actionWithTitle:@"取消" style:UIAlertActionStyleCancel handler:nil];
        //添加action
        [alertController addAction:confirmAction];
        [alertController addAction:cancelAction];
        //显示
        [self presentViewController:alertController animated:YES completion:nil];
    }else{
        if (indexPath.section == 1 && indexPath.row ==0) {
            AboutViewController *AW = [[AboutViewController alloc]init];
            [self.navigationController pushViewController:AW animated:YES];
            
        }else if (indexPath.section == 1 && indexPath.row == 1){
            YiBaoViewController *YC = [[YiBaoViewController alloc]init];
            [self.navigationController pushViewController:YC animated:YES];
            
            
        }else if (indexPath.row == 2){
            //创建提示框
            UIAlertController *alertController = [UIAlertController alertControllerWithTitle:@"拨打客服电话" message:@"110-120" preferredStyle:UIAlertControllerStyleAlert];
            //确定action
            UIAlertAction *confirmAction = [UIAlertAction actionWithTitle:@"确定" style:UIAlertActionStyleDefault handler:nil];
            //取消
            UIAlertAction *cancelAction = [UIAlertAction actionWithTitle:@"取消" style:UIAlertActionStyleCancel handler:nil];
            //添加action
            [alertController addAction:confirmAction];
            [alertController addAction:cancelAction];
            //显示
            [self presentViewController:alertController animated:YES completion:nil];
    
        }
    }
   
}

- (NSInteger)numberOfSectionsInTableView:(UITableView *)tableView{
    return 2;
}

- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section{
    if (section == 0) {
        return 4;
    }else
    {
    
        return 3;
    }
}
- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath{
    UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:cellID forIndexPath:indexPath];
    cell.accessoryType = UITableViewCellAccessoryDisclosureIndicator;
    if (indexPath.row == 0 && indexPath.section == 0 ) {
        cell.textLabel.text = @"意见反馈";
    }else if (indexPath.row == 1 && indexPath.section ==0){
    
    cell.textLabel.text = @"帮助中心";
    
    }else if (indexPath.row == 2 && indexPath.section ==0)
    {
    cell.textLabel.text = @"清除缓存";
    }else if (indexPath.row == 3 && indexPath.section ==0)
    {
        
        cell.textLabel.text = @"消息推送";
        
        UISwitch *switchView = [[UISwitch alloc] init];
        [switchView setOn:YES];
        cell.accessoryView = switchView;
        
        
        
    }else if (indexPath.row == 0 && indexPath.section ==1)
    {
    cell.textLabel.text = @"关于就医宝";
    
    
    }else if (indexPath.row == 1 && indexPath.section ==1)
    {
        cell.textLabel.text = @"医保使用规则";
    }else if (indexPath.row == 2 && indexPath.section ==1)
    {
        cell.textLabel.text = @"拨打客服电话";
    }
  //  NSArray *arr = @[ @[ @"意见反馈", @"帮助中心", @"清楚缓存" ], @[ @"关于就医宝", @"医保使用规则", @"检查更新", @"拨打客服电话" ] ];
    
    ;
        return cell;
}
- (void)viewDidLoad {
    [super viewDidLoad];
    [self setupUI];
   
    self.navigationItem.title = @"设置";
    // self.navigationItem.rightBarButtonItem = self.editButtonItem;
//    self.navigationItem.hidesBackButton = YES;
    
    
    // Do any additional setup after loading the view, typically from a nib.
}

-(void)setupUI{

    UITableView *tv = [[UITableView alloc]initWithFrame:self.view.bounds style:UITableViewStyleGrouped];
    
    tv.separatorStyle = UITableViewCellSeparatorStyleNone;
    tv.backgroundColor = [UIColor whiteColor];

    [self.view addSubview:tv];
    tv.delegate = self;
    tv.dataSource = self;
    [tv registerClass:[UITableViewCell class] forCellReuseIdentifier:cellID];



}
- (void)didReceiveMemoryWarning {
    [super didReceiveMemoryWarning];
    // Dispose of any resources that can be recreated.
}

@end
